package demo2;

class Shape {
    //属性....
    public void draw() {
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("菱形: ♦");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("圆形: ●");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("花: ❀");
    }
}
public class Test {
    /**
     * 使用父类定义数组,实现多态进行调用子类方法
     * @param args
     */
    public static void main3(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shape[] shapes = {rect,cycle,rect,cycle,flower};

        for(Shape shape:shapes) {
            shape.draw();
        }
    }
    public static void main2(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] strings = {"1","2","2","1","3"};

        for(String s:strings) {
            if(s.equals("1")) {
                rect.draw();
            }else if(s.equals("2")) {
                cycle.draw();
            }else {
                flower.draw();
            }
        }
    }
    public static void func(Shape shape) {
        shape.draw();
    }
    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        func(rect);
        func(cycle);
        func(flower);
    }
}
